package com.zzsy.shoppingpro.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zzsy.shoppingpro.R;
import com.zzsy.shoppingpro.app.Config;
import com.zzsy.shoppingpro.home.bean.HomeBean;

import java.util.List;

/**
 * Created by Administrator on 2019/8/19 0019.
 */

public class ChannelAdapter extends BaseAdapter {

    private Context context;
    private List<HomeBean.ResultBean.ChannelInfoBean> channelInfoBeans;

    public ChannelAdapter(Context mContext, List<HomeBean.ResultBean.ChannelInfoBean> channel_info) {
        this.context = mContext;
        this.channelInfoBeans = channel_info;
    }

    @Override
    public int getCount() {
        return channelInfoBeans == null ? 0 : channelInfoBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return channelInfoBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.item_channel,null);
            holder = new ViewHolder();
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        HomeBean.ResultBean.ChannelInfoBean channelInfoBean = channelInfoBeans.get(position);
        holder.imageView = convertView.findViewById(R.id.iv_channel);
        holder.tvChannel = convertView.findViewById(R.id.tv_channel);
        Glide.with(context)
                .load(Config.BASE_URl_IMAGE + channelInfoBean.getImage())
                .into(holder.imageView);
        holder.tvChannel.setText(channelInfoBean.getChannel_name());


        return convertView;
    }

    class ViewHolder{
        ImageView imageView;
        TextView tvChannel;
    }

}
